Completed
Push — master ( 2e96ee...51b9e4 )
by Rain
01:37
created

include.js ➔ $   B

Complexity

Conditions 1
Paths 414

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 414
dl 0
loc 4
rs 7.6342
c 0
b 0
f 0
nop 0
1
2
$(function () {
3
	
4
	var
5
		sAccount = window.rl.pluginSettingsGet('google-analytics', 'account'),
6
		sDomain = window.rl.pluginSettingsGet('google-analytics', 'domain_name'),
7
		bUniversalAnalytics = !!window.rl.pluginSettingsGet('google-analytics', 'universal_analytics'),
8
		bTrackPageview = !!window.rl.pluginSettingsGet('google-analytics', 'track_pageview'),
9
		bSendEvent = !!window.rl.pluginSettingsGet('google-analytics', 'send_events'),
10
		fSendEvent = null
11
	;
12
13
	if (sAccount && '' !== sAccount)
14
	{
15
		if (bUniversalAnalytics)
16
		{
17
			(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
18
				(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
19
				m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
20
			})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
21
22
			if (window.ga)
23
			{
24
				if (sDomain)
25
				{
26
					window.ga('create', sAccount, sDomain);
27
				}
28
				else
29
				{
30
					window.ga('create', sAccount);
31
				}
32
33
				if (bTrackPageview)
34
				{
35
					window.ga('send', 'pageview');
36
					window.setInterval(function () {
37
						window.ga('send', 'pageview');
38
					}, 1000 * 60 * 2);
39
				}
40
41
				if (bSendEvent)
42
				{
43
					fSendEvent = function(sCategory, sAction, sLabel) {
44
						window.ga('send', 'event', sCategory, sAction, sLabel);
45
					};
46
				}
47
			}
48
		}
49
		else
50
		{
51
			window._gaq = window._gaq || [];
52
			window._gaq.push(['_setAccount', sAccount]);
53
54
			if (sDomain)
55
			{
56
				window._gaq.push(['_setDomainName', sDomain]);
57
			}
58
59
			if (bTrackPageview)
60
			{
61
				window._gaq.push(['_trackPageview']);
62
				window.setInterval(function () {
63
					window._gaq.push(['_trackPageview']);
64
				}, 1000 * 60 * 2);
65
			}
66
67
			if (bSendEvent)
68
			{
69
				fSendEvent = function(sCategory, sAction, sLabel) {
70
					window._gaq.push(['_trackEvent', sCategory, sAction, sLabel]);
71
				};
72
			}
73
74
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
75
			ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
76
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
77
		}
78
79
		if (fSendEvent)
80
		{
81
			window.rl.addHook('ajax-default-response', function (sAction, oData, sType) {
82
				switch (sAction)
83
				{
84
					case 'Login':
85
					case 'SendMessage':
86
					case 'MessageMove':
87
					case 'MessageDelete':
88
						fSendEvent('RainLoop', sAction,
89
							'success' === sType && oData && oData['Result'] ? 'true' : 'false');
90
						break;
91
				}
92
			});
93
		}
94
	}
95
});